package service.impl;

import dao.UserDao;
import entity.User;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;
import service.UserService;

import java.util.List;

/**
 * Author:shixiaojun@itany.com
 * Date:2022/3/9 15:56
 * Version:1.0-SNAPSHOT
 */
@Service
@Transactional(propagation = Propagation.REQUIRED,rollbackFor = Exception.class,noRollbackFor = ArithmeticException.class,timeout = 2)
public class UserServiceImpl implements UserService {

    @Autowired
    private UserDao userDao;

    @Override
    public void register(String username, String password, String phone, String address) {
        try {
            Thread.sleep(3000);
        } catch (InterruptedException e) {
        }
        User user = new User(username,password,phone,address);
        userDao.insertUser(user);
        int i = 1/0;
    }

    @Transactional(propagation = Propagation.SUPPORTS,readOnly = true)
    @Override
    public List<User> findAll() {
        List<User> users = userDao.selectAll();
        return users;
    }
}
